package com.sgb.kjwl.view.ui.adapter.shopping;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.makeramen.roundedimageview.RoundedImageView;
import com.sgb.kjwl.R;
import com.sgb.kjwl.model.entity.Bean;
import com.swgk.core.util.UiUtil;
import com.swgk.core.util.MyMediaUtils;

import java.util.List;

/**
 * 作者:张磊
 * 日期:2018/6/20
 * 说明:指示器
 */
public class IndicatorAdapter extends BaseQuickAdapter<Bean, BaseViewHolder> {


    private boolean isHasVideo = false;//用于显示服务器视频图片为null的显示问题

    public IndicatorAdapter(List<Bean> beans) {
        super(R.layout.indicator_adapter, beans);
    }

    @Override
    protected void convert(BaseViewHolder helper, final Bean item) {
        helper.setVisible(R.id.iv_play, item.type == 1);
        RoundedImageView iv_img = helper.getView(R.id.iv_img);
        iv_img.setBorderColor(UiUtil.getColor(item.select ? R.color.color_FF4B10 : R.color.translucent));
        if (isHasVideo){
            if (helper.getAdapterPosition()==0){
                Glide.with(mContext).load(MyMediaUtils.setVideoFirstImg(item.url,mContext)).apply(new RequestOptions().centerCrop()).into(iv_img);
              //  iv_img.setImageBitmap(MediaUtils.setVideoFirstImg(item.url,mContext));
            }else {
                Glide.with(mContext).load(item.url).apply(new RequestOptions().centerCrop()).into(iv_img);
            }
        }else {
            Glide.with(mContext).load(item.url).apply(new RequestOptions().centerCrop()).into(iv_img);
        }
    }

    public void setIsHasVideo(boolean isHasVideo) {
        this.isHasVideo = isHasVideo;
    }
}
